package com.timothy.survey;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.SAXException;

public class SurveyXMLParseBiz {
	InputStream inputstream =null;
    
    public SurveyXMLParseBiz(String xmlpath){
        try {
            File f = new File(xmlpath);
            this.inputstream =new FileInputStream(f);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
    
    public List<Survey> saxParseXML( ) throws SAXException, IOException, ParserConfigurationException{
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser parser =factory.newSAXParser();
        SurveySaxHelp helper = new SurveySaxHelp();
        parser.parse(this.inputstream, helper);
        return helper.getList();
    }
    
    public static void main(String[] args) {
    	SurveyXMLParseBiz biz = new SurveyXMLParseBiz("E:\\workspace\\AndroidServer\\res\\survey.xml");
    	try {
			List<Survey> surveys = biz.saxParseXML();
			for(int i=0;i<surveys.size();i++){
				System.out.println(surveys.get(i).toString());
			}
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
